package com.lancer.dynamic.thread.pool.domain;


import io.swagger.v3.oas.annotations.media.Schema;
import org.apache.commons.lang3.StringUtils;

/**
 * @author mengdie.zhang
 * @Title:返回类
 * @Description：TODO
 * @date 2020/12/814:37
 **/
@Schema(defaultValue = "返回说明")
public class Result<T> {

    public static final String SERVER_ERR_MSG = "服务器异常，请联系系统管理员!";

    private Result() {
    }

    @Schema(defaultValue = "返回消息")
    private String message;
    @Schema(defaultValue = "返回数据")
    private T resultData;
    @Schema(defaultValue = "返回状态码")
    private int status;

    /**
     * 成功
     * @param data 返回数据
     * @return
     */
    public static <T> Result<T> success(T data) {

        return success("成功", data);
    }

    /**
     * 适用场景： 只需要返回消息
     * @param msg  返回消息
     * @return
     */
    public static <T> Result<T> success(String msg) {
        return success(msg, null);
    }

    /**
     * 成功
     * @param data 返回数据
     * @return
     */
    public static <T> Result<T> success(String msg, T data) {
        Result<T> result = new Result<>();
        result.message = StringUtils.isNotBlank(msg) ? msg : "成功";
        result.status = 1;
        result.resultData = data;
        return result;
    }

    /**
     * 失败
     * @param message 失败信息
     * @return
     */
    public static <T> Result<T> failed(String message) {
        Result<T> result = new Result<>();
        result.message = message;
        result.status = 0;
        return result;
    }
    /**
     * 失败
     * @param message 失败信息
     * @return
     */
    public static <T> Result<T> failed(String message, Integer status) {
        Result<T> result = new Result<>();
        result.message = message;
        result.status = status;
        return result;
    }
    /**
     * 失败返回数据
     * @param data 返回数据
     * @return
     */
    public static <T> Result<T> error(String message, T data) {
        Result<T> result = new Result<>();
        result.message = message;
        result.status = 0;
        result.resultData = data;
        return result;
    }



    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getResultData() {
        return resultData;
    }

    public void setResultData(T resultData) {
        this.resultData = resultData;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }
}
